/*
 * @Author: 飞越疯人院 353362604@qq.com
 * @Date: 2022-09-22 09:44:20
 * @LastEditors: NaN 353362604@qq.com
 * @LastEditTime: 2023-01-12 16:00:29
 * @FilePath: \adminstration\src\Common\Modal\ThrModalList\SampleEnclosure.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

// 项目阶段

import axios from 'axios'
import { setValueEnumData, setFieldPropsOptions } from '../../Router/MenuBoxList'
import { BuiltInData, TreeFilterData } from '../config'
import { API_LIST } from '../../Api/Api'

export const ProjectFormItemValue = async ({ data }) => {
    const SceneList = await setValueEnumData({ url: 'getScenes' })
    const RegionTree = TreeFilterData(await setFieldPropsOptions({ url: 'getProjectRegionTree' }))
    const { data: Value } = await axios.get(API_LIST([data.uuid])['getProjectFormItemValueListWithValue'], {
        params: { OrganizationUuid: data.uuid },
    })
    let backfill = {}
    let columns = []

    const formItemList = (projectFormItemCode, projectFormItemName) => ({
        currentPeriod: {
            dataIndex: projectFormItemCode,
            title: projectFormItemName,
            valueType: 'select',
            className: 'RemarkForm',
            valueEnum: BuiltInData.CurrentPeriod,
        },
        scene: {
            dataIndex: projectFormItemCode,
            title: projectFormItemName,
            valueType: 'select',
            className: 'RemarkForm',
            valueEnum: SceneList,
        },
        projectType: {
            dataIndex: projectFormItemCode,
            title: projectFormItemName,
            valueType: 'select',
            className: 'RemarkForm',
            valueEnum: BuiltInData.projectType,
        },
        roadLevel: {
            dataIndex: projectFormItemCode,
            title: projectFormItemName,
            valueType: 'select',
            className: 'RemarkForm',
            valueEnum: BuiltInData.roadLevel,
        },
        isRenew: {
            dataIndex: projectFormItemCode,
            title: projectFormItemName,
            valueType: 'select',
            className: 'RemarkForm',
            valueEnum: BuiltInData.isRenew,
        },
        feasibleStatus: {
            dataIndex: projectFormItemCode,
            title: projectFormItemName,
            valueType: 'select',
            className: 'RemarkForm',
            valueEnum: BuiltInData.isYesText,
        },
        isInherit: {
            dataIndex: projectFormItemCode,
            title: projectFormItemName,
            valueType: 'select',
            className: 'RemarkForm',
            valueEnum: BuiltInData.isYesText,
        },
        isCompleted: {
            dataIndex: projectFormItemCode,
            title: projectFormItemName,
            valueType: 'select',
            className: 'RemarkForm',
            valueEnum: BuiltInData.isYesText,
        },

        certApprovalDate: {
            dataIndex: projectFormItemCode,
            title: projectFormItemName,
            valueType: 'Date',
            className: 'RemarkForm',
        },
        feasibleDate: {
            dataIndex: projectFormItemCode,
            title: projectFormItemName,
            valueType: 'Date',
            className: 'RemarkForm',
        },
        planCompleteDate: {
            dataIndex: projectFormItemCode,
            title: projectFormItemName,
            valueType: 'Date',
            className: 'RemarkForm',
        },
        commencementDate: {
            dataIndex: projectFormItemCode,
            title: projectFormItemName,
            valueType: 'Date',
            className: 'RemarkForm',
        },

        towns: {
            dataIndex: projectFormItemCode,
            title: projectFormItemName,
            className: 'RemarkForm',
            valueType: 'treeSelect',
            fieldProps: {
                options: RegionTree,
                fieldNames: { label: 'tableName', value: 'uuid' },
            },
        },
        remark: {
            dataIndex: projectFormItemCode,
            title: projectFormItemName,
            valueType: 'textarea',
            className: 'RemarkForm',
        },
    })
    Value.forEach(({ projectFormItemUuid, projectFormItemName, projectFormItemCode, value, formItemType }) => {
        backfill = { ...backfill, [projectFormItemCode]: value }
        formItemList()[projectFormItemCode]
            ? (columns = [...columns, formItemList(projectFormItemCode, projectFormItemName)[projectFormItemCode]])
            : (columns = [
                  ...columns,
                  {
                      dataIndex: projectFormItemCode,
                      title: projectFormItemName,
                      valueType: 'input',
                      className: 'RemarkForm',
                  },
              ])
    })

    let dataList = {
        url: 'ProjectFormItemValue',
        uuid: data.uuid,
        type: '项目配置',
        width: 600,
        classification: 'FormModal',
        hideInSearch: true,
        pageSize: 10,
        path: [data.uuid],
        params: {},
        added: 'posProjectFormItemValueSyncObject',
        modify: 'posProjectFormItemValueSyncObject',
        backfill,
        columns,
    }
    return dataList
}
